#include "tablecontainerwidget.h"
#include "ui_tablecontainerwidget.h"
#include "tablevieweventfilter.h"
#include <QStandardItemModel>

CTableContainerWidget::CTableContainerWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CTableContainerWidget),
    m_pTableModel(new QStandardItemModel(this))
{
    ui->setupUi(this);
    InitTableView();
}

CTableContainerWidget::~CTableContainerWidget()
{
    delete ui;
}

void CTableContainerWidget::InitTableView()
{
    m_pTableModel->setHorizontalHeaderLabels(QStringList() << tr("") << tr("Name") << tr("Count"));
    m_pTableModel->setRowCount(1);
    m_pTableModel->setItem(0,0,new QStandardItem(QIcon(":/resources/image/error.png"), tr("")));
    m_pTableModel->setItem(0,1,new QStandardItem(tr("Qt")));
    m_pTableModel->setItem(0,2, new QStandardItem(tr("5")));
    ui->tableView->setModel(m_pTableModel);

    ui->tableView->verticalHeader()->setVisible(false);
    ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableView->horizontalHeader()->setStretchLastSection(true);
    ui->tableView->setColumnWidth(0, 24);

    ui->tableView->viewport()->installEventFilter(new CClearSelectionEventFilter(ui->tableView));
}
